package com.one.group.controller;

import com.one.group.service.chatHistoryService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * {@code @Create:}  2025-10-14  15 : 28
 * {@code @Author:} Cherry
 * {@code @ToAuthor:} 凡是发生,皆有利于我。
 * ------------------------------------
 * {@code @note:}
 */

@SuppressWarnings({"all"})
@RestController
public class ChatController {

    @Resource
    private ChatClient chatClient;

    @Resource
    private chatHistoryService chatHistoryService;

    @GetMapping("/chat/v1")
    @Operation(summary = "deepseek聊天调用")
    public String chat(@RequestParam String msg, String chatId) {
        chatHistoryService.save("chat", chatId);
        return chatClient.prompt().user(msg)
                .advisors(advisorSpec -> advisorSpec.param(ChatMemory.CONVERSATION_ID, chatId))
                .call()
                .content();
    }

    @GetMapping("/chat/v2")
    @Operation(summary = "deepseek聊天流式调用")
    public Flux<String> chat2(@RequestParam String msg, String chatId) {
        chatHistoryService.save("chat", chatId);
        Flux<String> stream = chatClient.prompt().user(msg)
                .advisors(advisorSpec -> advisorSpec.param(ChatMemory.CONVERSATION_ID, chatId))
                .stream()
                .content();
        return stream;
    }
}
